﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace UIapp
{
    public static class Comun
    {
        public static Point frmMainLocation;
        public static Size frmMainSize;

        static Plantillas.frmLoading _loadingFRM;

        static public void ShowMessage(string s, MessageBoxIcon ico)
        {
            MessageBox.Show(s, "G.S.Q.", MessageBoxButtons.OK, ico);
        }

        public static void ShowMessage(Exception ex)
        {
            new Plantillas.frmErrorMessage(ex).ShowDialog();
        }

        public static void ShowMessage(GSQ.BusinessEntities.EntityBase value)
        {
            StringBuilder sb = new StringBuilder();
            foreach (GSQ.BusinessEntities.BrokenRule i in value.BrokenRules)
            {
                sb.AppendLine(string.Format("-> Campo {0} {1}\r", i.PropertyName, i.Message));
            }
            new Plantillas.frmErrorMessage("Hay campos que no están correctamente completados", sb.ToString()).ShowDialog();
        }

        public static void ShowLoadingFRM()
        {
            if (_loadingFRM == null)
            {
                _loadingFRM = new Plantillas.frmLoading();
            }

            _loadingFRM.Size = new Size(frmMainSize.Width - 15, frmMainSize.Height - 40);
            _loadingFRM.Location = new Point(frmMainLocation.X + 8, frmMainLocation.Y + 30);             
            _loadingFRM.ShowDialog();
        }

        public static void CloseLoadingFRM()
        {
            _loadingFRM.CloseFrm();
            _loadingFRM = null;
        }
    }
}
